#ifndef __ASTAR_FILE_H__
#define __ASTAR_FILE_H__

#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>

class ASTAR_FILE
{
	public:

	virtual void read( void *dst, unsigned int bytes ) = 0;
	virtual void write( const void *src, unsigned int bytes ) = 0;
	virtual void seek( unsigned int pos ) = 0;
	virtual unsigned int size( void ) = 0;
	virtual unsigned int tell( void ) = 0;
	virtual int getchr( void );
	virtual void gets( char *dst, int maxsize );
	virtual bool eof( void );
	virtual unsigned short get_le_short( void );
	virtual unsigned short get_be_short( void );
	virtual float getfloat( void );
};

class ASTAR_FILE_DISK: public ASTAR_FILE
{
	FILE *m_fptr;
	unsigned int m_size;

	public:

	ASTAR_FILE_DISK( const char *filename );
	~ASTAR_FILE_DISK();
	void read( void *dst, unsigned int bytes );
	void write( const void *src, unsigned int bytes );
	void seek( unsigned int pos );
	unsigned int tell( void );
	unsigned int size( void );
};

class ASTAR_FILE_RAM: public ASTAR_FILE
{
	unsigned char *m_buffer;
	unsigned char *m_pos;
	unsigned int m_size;

	public:

	ASTAR_FILE_RAM( ASTAR_FILE &file );
	~ASTAR_FILE_RAM();
	inline int getchr( void )
	{
		int rval = *m_pos;
		m_pos++;
		return rval; 
	}
	void read( void *dst, unsigned int bytes )
	{
		memcpy( dst, m_pos, bytes );
		m_pos += bytes;
	}

	void write( const void *src, unsigned int bytes )
	{
		assert( 0 );
	}

	void seek( unsigned int pos )
	{
		m_pos = m_buffer + pos;
	}
	unsigned int tell( void )
	{
		return m_pos - m_buffer;
	}
	unsigned int size( void )
	{
		return m_size; 
	}
};

#endif

